package com.wangdf;

import java.io.File;  
import java.io.FileWriter;  
import java.io.Writer;  
import java.util.HashMap;  
import java.util.Map;  
   
import junit.framework.TestCase;  
import freemarker.template.Configuration;  
import freemarker.template.Template;  
   
   
public class FreeTest extends TestCase{  
   
    @SuppressWarnings("unchecked")
	public static void testFreemarker01() throws Exception{  
       String dir = "E:/NFrame/eclipsespace/FreeMarkerTest/src/com/wangdf";  
         
       Configuration cfg = new Configuration();  
         
       //从什么地方加载模板文件 
       cfg.setDirectoryForTemplateLoading(new File(dir));  
         
       //加载模板  
       Template template = cfg.getTemplate("test01.ftl");  
         
       //定义数据 
       @SuppressWarnings("rawtypes")
	Map root = new HashMap();  
       root.put("stringvalue", "哈哈~");  
         
       //定义输出 
       Writer out = new FileWriter(dir+"/test01_out.txt");  
         
       template.process(root, out);  
         
       out.flush();  
       out.close();  
    }  
    
    public static void main(String[] args) {
    	try {
			testFreemarker01();
		} catch (Exception e) {
			e.printStackTrace();
		}
    	System.out.println("DONE!");
	}
   
}  